home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / searchForRunTimeCommandWindo < prev    next >
Encoding:
Text File  |  2003-07-17  |  8.2 KB  |  268 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  20 December 1999
  22. //
  23. //  Description:
  24. //      This script implements the "Search for a Command" window.
  25. //
  26. //        The window is accessed from the Hotkey Editor window and its
  27. //        main purpose is to allow users a simple searching of the commands
  28. //        available for attaching to hotkeys.
  29. //
  30.  
  31. /*
  32. //
  33. //    These are the local and global procedures defined in this file.  As well
  34. //    as the unique names of the UI objects created.
  35. //
  36. // ----------------------------------------------------------------------
  37. //
  38. spacing(string $str, string $longest)
  39.  
  40. searchForRunTimeCommandWindowSearch()
  41. searchForRunTimeCommandWindowPrintHelp()
  42. searchForRunTimeCommandWindowClose()
  43. searchForRunTimeCommandWindow()
  44.  
  45. SearchForRunTimeCommandWindow
  46. SearchForRunTimeCommandWindowSearchFieldGrp
  47. SearchForRunTimeCommandWindowSearchResultField
  48. */
  49.  
  50. proc string spacing(string $str, string $longest)
  51. //
  52. //    Description:
  53. //        Return a string containing the number of spaces required to
  54. //        make the passed in string argument the same length as the
  55. //        passed in "longest" string.
  56. //
  57. //    Example:
  58. //        
  59. //        if  $str is                    "Hello"
  60. //        and $longest is                "A longer string"
  61. //
  62. //        then the return string will be "          ".
  63. //                            
  64. {
  65.     string $result = "";
  66.     string $spaces = "                                                  ";
  67.     
  68.     $numberOfSpacesNeeded = size($longest) - size($str);
  69.  
  70.     if (0 < $numberOfSpacesNeeded) {
  71.         if ($numberOfSpacesNeeded > size($spaces)) {
  72.             $numberOfSpacesNeeded = size($spaces);
  73.         }
  74.         $result = `substring $spaces 1 $numberOfSpacesNeeded`;
  75.     }
  76.     
  77.     return $result;
  78. }
  79.  
  80. global proc searchForRunTimeCommandWindowSearch()
  81. //
  82. //    Description:
  83. //        This function is called when the user changes the text in the
  84. //        search field.
  85. //
  86. {
  87.     string $result = "", $command, $match[];
  88.     string $longestNameMatch, $longestCategoryMatch;
  89.     int $matchIndex = 0, $numberOfMatches;
  90.     
  91.     string $searchFor = `textFieldGrp -query -text 
  92.         SearchForRunTimeCommandWindowSearchFieldGrp`;
  93.     string $category, $nameHeader = "Command Name";
  94.     string $categoryHeader = "Category", $commandHeader = "Command";
  95.     string $spaceAfterName = "    ", $spaceAfterCategory = "    ";
  96.     
  97.     if ("" == $searchFor) {
  98.         //
  99.         //    Check for empty search string.
  100.         //
  101.         searchForRunTimeCommandWindowPrintHelp();
  102.  
  103.     } else {
  104.         //
  105.         //    Look for matches on the command's name and the actual command.
  106.         //
  107.         string $runTimeCommands[] = `runTimeCommand -query -commandArray`;
  108.         for ($runTimeCommand in $runTimeCommands) {
  109.             $command = `runTimeCommand -query -command $runTimeCommand`;
  110.             if (gmatch($runTimeCommand, $searchFor) ||
  111.                 gmatch($command, $searchFor)) {
  112.                 $match[$matchIndex++] = $runTimeCommand;
  113.             }
  114.         }
  115.  
  116.         $numberOfMatches = size($match);
  117.         
  118.         if (0 < $numberOfMatches) {
  119.             //
  120.             //    Matches found.
  121.             //
  122.             
  123.             //    Look for the longest command name and category name so we can 
  124.             //    line up the results.
  125.             //
  126.             $longestNameMatch = $nameHeader;
  127.             for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
  128.                 if (size($match[$matchIndex]) > size($longestNameMatch)) {
  129.                     $longestNameMatch = $match[$matchIndex];
  130.                 }
  131.             }
  132.             $longestCategoryMatch = $categoryHeader;
  133.             for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
  134.                 $category = `runTimeCommand -query -category $match[$matchIndex]`;
  135.                 if (size($category) > size($longestCategoryMatch)) {
  136.                     $longestCategoryMatch = $category;
  137.                 }
  138.             }
  139.  
  140.             //    Print out a header for the results.
  141.             //
  142.             $result = $nameHeader + spacing($nameHeader, $longestNameMatch) 
  143.                 + $spaceAfterName + $categoryHeader
  144.                 + spacing($categoryHeader, $longestCategoryMatch)
  145.                 + $spaceAfterCategory + $commandHeader + "\n"
  146.                 + "-----------------------------------"
  147.                 + "-----------------------------------\n";
  148.             
  149.             //    For each match print out the command name, category of the
  150.             //    command and the actual command.
  151.             //
  152.             for ($matchIndex = 0; $matchIndex < $numberOfMatches; $matchIndex++) {
  153.                 $result += $match[$matchIndex];
  154.  
  155.                 $category = `runTimeCommand -query -category $match[$matchIndex]`;
  156.                 $result += spacing($match[$matchIndex], $longestNameMatch)
  157.                     + $spaceAfterName + $category
  158.                     + spacing($category, $longestCategoryMatch)
  159.                     + $spaceAfterCategory
  160.                     + `runTimeCommand -query -command $match[$matchIndex]` + "\n";
  161.             }
  162.  
  163.         } else {
  164.             //
  165.             //    No matches found.
  166.             //
  167.             $result = "No matches found on \"" + $searchFor + "\".\n";
  168.             
  169.             //    Does the search string have any *'s in it?  If not then
  170.             //    suggest that the user should add one.
  171.             //
  172.             if (gmatch($searchFor, "*[**]*")) {
  173.             } else {
  174.                 $result += "\nTry adding an asterisk or two, e.g. \"*" 
  175.                     + $searchFor + "*\".\n";
  176.             }
  177.         }
  178.         scrollField -edit -text $result -insertionPosition 1
  179.             SearchForRunTimeCommandWindowSearchResultField;
  180.     }
  181. }
  182.  
  183. global proc searchForRunTimeCommandWindowPrintHelp()
  184. //
  185. //    Description:
  186. //        Print out a help message for the user.  Describe what is
  187. //        expected in the search field and give some examples.
  188. //
  189. {
  190.     string $help = "Enter a case sensitive search string in the\n"
  191.             + "field above.\n\n"
  192.             + "Some examples are:\n"
  193.             + "  *Scene\n"
  194.             + "  Display*\n"
  195.             + "  *UI*\n"
  196.             + "  *[Mm]enu*\n";
  197.     scrollField -edit -text $help -insertionPosition 1
  198.         SearchForRunTimeCommandWindowSearchResultField;
  199.     textFieldButtonGrp -edit -text "" SearchForRunTimeCommandWindowSearchFieldGrp;
  200. }
  201.  
  202. global proc searchForRunTimeCommandWindowClose()
  203. //
  204. //    Description:
  205. //        This function is called when the user presses the close button.
  206. //
  207. {
  208.     //    Delete the window.
  209.     //
  210.     deleteUI -window SearchForRunTimeCommandWindow;
  211. }
  212.  
  213. global proc searchForRunTimeCommandWindow()
  214. //
  215. //    Description:
  216. //        Create a window for searching the runTimeCommands.
  217. //
  218. {
  219.     //    If the window already exists then just show it and return.
  220.     //
  221.     if (`window -exists SearchForRunTimeCommandWindow`) {
  222.         showWindow SearchForRunTimeCommandWindow;
  223.         return;
  224.     }
  225.  
  226.     //    Otherwise, build the window.
  227.     //
  228.     window -title "Search for Command" 
  229.         -iconName "Find Cmd"
  230.         SearchForRunTimeCommandWindow;
  231.  
  232.     string $form = `formLayout`;
  233.     
  234.     string $description = "Enter case sensitive search string"
  235.         + " (for example, *ndo*)";
  236.  
  237.     string $searchFor = `textFieldButtonGrp -label "Search for"
  238.         -buttonLabel "Help"
  239.         -buttonCommand ("searchForRunTimeCommandWindowPrintHelp")
  240.         -adjustableColumn2 2 
  241.         -changeCommand ("searchForRunTimeCommandWindowSearch")
  242.         -annotation $description
  243.         SearchForRunTimeCommandWindowSearchFieldGrp`;
  244.  
  245.     string $results = `scrollField -editable false -height 250
  246.         SearchForRunTimeCommandWindowSearchResultField`;
  247.     
  248.     string $close = `button -label "Close"
  249.         -command ("searchForRunTimeCommandWindowClose")`;
  250.     
  251.     formLayout -edit
  252.         -attachForm    $searchFor "top"    5
  253.         -attachForm    $searchFor "left"   5
  254.         -attachNone    $searchFor "bottom"
  255.         -attachForm    $searchFor "right"  5
  256.         -attachControl $results   "top"    5 $searchFor
  257.         -attachForm    $results   "left"   5
  258.         -attachControl $results   "bottom" 5 $close
  259.         -attachForm    $results   "right"  5
  260.         -attachNone    $close     "top"
  261.         -attachForm    $close     "left"   5
  262.         -attachForm    $close     "bottom" 5
  263.         -attachForm    $close     "right"  5
  264.         $form;
  265.     
  266.     showWindow SearchForRunTimeCommandWindow;
  267. }
  268.